<template>
	<view class='page_cont'>
		<jobItem :jobs="jobs" :status="3" v-if="type==1"></jobItem>
		<teacherItem :teachers="teachers" :status="3" v-if="type==2"></teacherItem>
		<view class='no_cont' v-if="show_nav">
			<view class="no_box">
			    <view class='title'>暂时还没有接受记录哦</view>
				<!-- <view class='text'>积极的人生，才有更好的收获！</view> -->
			</view>
			<view class='nav_btn' @click="nav_home">去首页</view>
		</view>
	</view>
</template>

<script>
	import JobItem from "../../components/jobItem.vue"
	import TeacherItem from "../../components/teacherItem.vue"
	import {positionInfoGetByIds,getInvitationTeacherList} from"../../api/myPage.js"
	import util from "../../utils/util.js"
	export default{
		components: {
			jobItem: JobItem,
			teacherItem: TeacherItem
		},
		data(){
			return {
				queryList:{
					type: 1,
					status:2,
					lat:null,
					lng:null,
					sidx: "ti.create_time",
					order: "desc",
					currentPage:1,
					pageSize:10
				},
				type: '',
				jobs: [],
				teachers: [],
				show_nav: false
			}
		},
		onLoad(options) {
			var that=this;
			that.type=options.type
			that.queryList.type=options.type==1?2:1
			const address = uni.getStorageSync('user_address')
			that.queryList.lat=address.lat
			that.queryList.lng=address.lng
		},
		onShow(){
			this.jobs = []
			this.teachers = []
			this.show_nav=false
			this.queryList.currentPage = 1
			this.getList()
		},
		onReachBottom(){
			if(this.type==1){
				if(this.jobs.length<this.total){
					this.queryList.currentPage++
					this.getList()
				}else{
					util.page_show_toast('没有更多了',1500)
				}
			}
			if(this.type==2){
				if(this.teachers.length<this.total){
					this.queryList.currentPage++
					this.getList()
				}else{
					util.page_show_toast('没有更多了',1500)
				}
			}
		},
		methods:{
			// 回首页
			nav_home(){
				uni.switchTab({
					url: '../../pages/index/index'
				})
			},
			getList(){
				uni.showLoading({})
				if(this.type==1){
					positionInfoGetByIds(this.queryList).then(res=>{
						uni.hideLoading()
						res.data.data.iPage.records.forEach((item)=>{
							item.space=item.distance>1000?(item.distance/1000).toFixed(2):item.distance;
							item.salary = item.salaryMin==0?"面议":`${item.salaryMin/1000}-${item.salaryMax/1000}k/月`
						})
						const {total,records} = res.data.data.iPage
						this.jobs.push(...records)
						this.total = total
						if(total==0){
							this.show_nav=true
						}
					})
				}
				if(this.type==2){
					getInvitationTeacherList(this.queryList).then(res=>{
						uni.hideLoading()
						res.data.data.iPage.records.forEach((item)=>{
							item.age=item.birthday?new Date().getFullYear()-new Date(item.birthday).getFullYear():'';
							item.workYear=item.joinWorkTime?new Date().getFullYear()-new Date(item.joinWorkTime).getFullYear():'';
							item.salary = item.salaryMin==0||!item.salaryMin?"面议":`${item.salaryMin/1000}-${item.salaryMax/1000}k/月`
							item.works.forEach((itm)=>{
								itm.start=util.formatTime1(new Date(itm.entryTime),1);
								itm.end=util.formatTime1(new Date(itm.quitTime),1)
							})
							if(item.works.length>0){
								item.maxIndex=util.getMaxIndex(item.works)
							}
						})
						const {total,records} = res.data.data.iPage
						this.teachers.push(...records)
						this.total = total
						if(total==0){
							this.show_nav=true
						}
					})
				}
			}
		}
	}
</script>

<style lang='scss'>
	page{
		background: #F6F7F9;
		.page_cont{
			width: 100%;
			.no_cont{
				width: 520rpx;
				margin: 110rpx auto 0 auto;
				.no_box{
					width: 100%;
					height: 520rpx;
					box-sizing: border-box;
					padding-top: 386rpx;
					background: url("https://ossdev0.jiabala.com/7XyPjGSZsyaek") no-repeat 0 0/100% 100%;
					.title{
						text-align: center;
						height: 50rpx;
						font-size: 32rpx;
						font-weight:400;
						line-height: 50rpx;
						color: #3F4A58;
					}
					.text{
						margin-top: 8rpx;
						text-align: center;
						height: 40rpx;
						font-size: 28rpx;
						font-weight:400;
						line-height: 40rpx;
						color: #798594;
					}
				}
				.nav_btn{
					width: 272rpx;
					margin: auto;
					height: 88rpx;
					background: #5B90FF;
					text-align: center;
					font-size: 30rpx;
					font-weight: 400;
					line-height: 88rpx;
					color:#fff;
					letter-spacing:2rpx;
					border-radius: 16rpx;
				}
			}
		}
	}
</style>